# encoding: utf-8

class Topic < ActiveRecord::Base
  belongs_to  :project,
              :touch => true

  has_one     :bug

  belongs_to  :user

  has_many    :replies,
              :dependent  =>  :destroy

  # Validations
  validates :project_id,
            :presence     =>  true,
            :numericality =>  { :only_integer => true,
                                :greater_than => 0  }

  validates :user_id,
            :presence     =>  true,
            :numericality =>  { :only_integer => true,
                                :greater_than => 0  }

  validates :name, :presence => true
  validates :name, :length   => { :within => 5..255 }, :unless => "self.name.empty?"
          
  validates :description, :presence => true
  validates :description, :length   => { :within => 5..5000 }, :unless => "self.description.empty?"
end

# == Schema Information
#
# Table name: topics
#
#  id          :integer         not null, primary key
#  project_id  :integer
#  user_id     :integer
#  name        :string(255)
#  description :text
#  created_at  :datetime
#  updated_at  :datetime
#

